package gatperdut.chato.core.interpreter.actions;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.interpreter.actions.generic.Action;
import gatperdut.chato.core.interpreter.grammar.comminfo.SetInfo;

public class SetAction extends Action {

    public SetAction( SetInfo info, BaseController entityController ) {
        super( info, entityController );
    }

    @Override
    public CommandExecutionResult perform() {
        checkForRunningCraft();

        switch ( getInfo().getSetType() ) {
        case ACCEPTGIVE:
            getEntityController().setAcceptGive( getInfo().isOn() );
            if ( getInfo().isOn() ) {
                getEntityController().tx( "You will now accept items others may give you." );
            }
            else {
                getEntityController().tx( "You will no longer accept items others may give you." );
            }
            break;
        case PACIFIST:
            getEntityController().setPacifist( getInfo().isOn() );
            if ( getInfo().isOn() ) {
                getEntityController().tx( "You are now in pacifist mode." );
                getEntityController().getCombatController().handleBecomingPacifist();
            }
            else {
                getEntityController().tx( "You are no longer in pacifist mode." );
            }
            break;
        default:
            throw new IllegalArgumentException( "Unknown SetType." );
        }

        return CommandExecutionResult.OK;
    }

    @Override
    public boolean interruptsCrafting() {
        return false;
    }

    @Override
    public SetInfo getInfo() {
        return (SetInfo) super.getInfo();
    }

}
